home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / BASESTORAGE.PY < prev    next >
Encoding:
Python Source  |  2000-08-08  |  8.2 KB  |  233 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64. """Handy standard storage machinery
  65. """
  66. __version__='$Revision: 1.7.12.1 $'[11:-2]
  67.  
  68.  
  69. import time, bpthread, UndoLogCompatible
  70. from POSException import UndoError
  71. from TimeStamp import TimeStamp
  72. z64='\0'*8
  73.  
  74. class BaseStorage(UndoLogCompatible.UndoLogCompatible):
  75.     _transaction=None
  76.     _serial=z64
  77.  
  78.     def __init__(self, name, base=None):
  79.         
  80.         self.__name__=name
  81.  
  82.         # Allocate locks:
  83.         l=bpthread.allocate_lock()
  84.         self._lock_acquire=l.acquire
  85.         self._lock_release=l.release
  86.         l=bpthread.allocate_lock()
  87.         self._commit_lock_acquire=l.acquire
  88.         self._commit_lock_release=l.release
  89.  
  90.         t=time.time()
  91.         t=self._ts=apply(TimeStamp,(time.gmtime(t)[:5]+(t%60,)))
  92.         self._serial=`t`
  93.         if base is None: self._oid='\0\0\0\0\0\0\0\0'
  94.         else:            self._oid=base._oid
  95.  
  96.     def abortVersion(self, src, transaction):
  97.         if transaction is not self._transaction:
  98.             raise POSException.StorageTransactionError(self, transaction)
  99.         return []
  100.  
  101.     def close(self): pass
  102.  
  103.     commitVersion=abortVersion
  104.  
  105.     def getName(self): return self.__name__
  106.     def getSize(self): return len(self)*300 # WAG!
  107.     def history(self, oid, version, length=1): pass
  108.                     
  109.     def modifiedInVersion(self, oid): return ''
  110.  
  111.     def new_oid(self, last=None):
  112.         if last is None:
  113.             self._lock_acquire()
  114.             try:
  115.                 last=self._oid
  116.                 d=ord(last[-1])
  117.                 if d < 255: last=last[:-1]+chr(d+1)
  118.                 else:       last=self.new_oid(last[:-1])
  119.                 self._oid=last
  120.                 return last
  121.             finally: self._lock_release()
  122.         else:
  123.             d=ord(last[-1])
  124.             if d < 255: return last[:-1]+chr(d+1)+'\0'*(8-len(last))
  125.             else:       return self.new_oid(last[:-1])
  126.  
  127.     def registerDB(self, db, limit): pass # we don't care
  128.  
  129.     def supportsUndo(self): return 0
  130.     def supportsVersions(self): return 0
  131.         
  132.     def tpc_abort(self, transaction):
  133.         self._lock_acquire()
  134.         try:
  135.             if transaction is not self._transaction: return
  136.             self._abort()
  137.             self._clear_temp()
  138.             self._transaction=None
  139.             self._commit_lock_release()
  140.         finally: self._lock_release()
  141.  
  142.     def _abort(self):
  143.         """Subclasses should rededine this to supply abort actions"""
  144.         pass
  145.  
  146.     def tpc_begin(self, transaction):
  147.         self._lock_acquire()
  148.         try:
  149.             if self._transaction is transaction: return
  150.             self._lock_release()
  151.             self._commit_lock_acquire()
  152.             self._lock_acquire()
  153.             self._transaction=transaction
  154.             self._clear_temp()
  155.  
  156.             user=transaction.user
  157.             desc=transaction.description
  158.             ext=transaction._extension
  159.             if ext: ext=dumps(ext,1)
  160.             else: ext=""
  161.             self._ude=user, desc, ext
  162.  
  163.             t=time.time()
  164.             t=apply(TimeStamp,(time.gmtime(t)[:5]+(t%60,)))
  165.             self._ts=t=t.laterThan(self._ts)
  166.             self._serial=`t`
  167.  
  168.             self._begin(self._serial, user, desc, ext)
  169.             
  170.         finally: self._lock_release()
  171.  
  172.     def _begin(self, tid, u, d, e):
  173.         """Subclasses should rededine this to supply
  174.         transaction start actions"""
  175.         pass
  176.  
  177.     def tpc_vote(self, transaction): pass
  178.  
  179.     def tpc_finish(self, transaction, f=None):
  180.         self._lock_acquire()
  181.         try:
  182.             if transaction is not self._transaction: return
  183.             if f is not None: f()
  184.  
  185.             u,d,e=self._ude
  186.             self._finish(self._serial, u, d, e)
  187.             self._clear_temp()
  188.         finally:
  189.             self._ude=None
  190.             self._transaction=None
  191.             self._commit_lock_release()
  192.             self._lock_release()
  193.  
  194.     def _finish(self, tid, u, d, e):
  195.         """Subclasses should rededine this to supply commit actions"""
  196.         pass
  197.  
  198.     def undo(self, transaction_id):
  199.         raise UndoError, 'non-undoable transaction'
  200.  
  201.     def undoLog(self, first, last, filter=None): return ()
  202.  
  203.     def versionEmpty(self, version): return 1
  204.  
  205.     def versions(self, max=None): return ()
  206.  
  207.     def pack(self, t, referencesf): pass
  208.  
  209.     def loadSerial(self, oid, serial):
  210.         raise POSException.Unsupported, (
  211.             "Retrieval of historical revisions is not supported")
  212.